<?php
	//if we already submitted the file
	if (!empty($this->data[file_name]))
	{
		//save/cancel links
		if ($this->all_backuped)
			$this->helpers->html->link('/spanel/'.$this->name.'/RestorePage/'.str_replace("_", "@", $this->request->post[system_name]).'/'.str_replace("_", "@", $this->request->post[file_name]).'/'.str_replace("_", "@", $this->backupDate), LANG_RESTORE_THE_LATEST, "class='button'");
		echo " ";
		$this->helpers->html->link('/spanel/', LANG_ON_MAIN_PAGE, "class='button' id = 'main_page_link'");
		
		if ($this->backuped)
		{
			echo "<br/><br/>".LANG_ATTENTION_WRITE;
		}
		
		//menu item code
		$this->helpers->html->link('', '', 'name = "menu_item"');
		echo '<br /><br />'.LANG_MENU_ITEM_CODE." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedString($this->data[menu_item], false);
		
		//language constants
		$this->helpers->html->link('', '', 'name = "lang_const"');
		echo '<br /><br />'.LANG_LANG_CONSTANTS." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedString($this->data[constant_defines], false);
		
		//generated model file
		$this->helpers->html->link('', '', 'name = "model"');
		echo '<br /><br />'.LANG_MODEL." ({$this->data[file_name]}.php)"." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/models/".$this->data[file_name].'.php');

		//generated controller file
		$this->helpers->html->link('', '', 'name = "controller"');
		echo '<br />'.LANG_CONTROLLER." ({$this->data[file_name]}.php)"." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/controllers/".$this->data[file_name].'.php');		
		echo '<br />';
		
		//generated add page file
		$this->helpers->html->link('', '', 'name = "add_page"');
		echo '<br />'.LANG_ADD." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/views/".$this->data[file_name].'/add.php');		
		echo '<br />';

		//generated edit page file
		$this->helpers->html->link('', '', 'name = "edit_page"');
		echo '<br />'.LANG_EDIT." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/views/".$this->data[file_name].'/edit.php');		
		echo '<br />';

		//generated view page file
		$this->helpers->html->link('', '', 'name = "view_page"');
		echo '<br />'.LANG_VIEW." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/views/".$this->data[file_name].'/view.php');		
		echo '<br />';
		
		//generated delete page file
		$this->helpers->html->link('', '', 'name = "delete_page"');
		echo '<br />'.LANG_DELETE." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/views/".$this->data[file_name].'/delete.php');		
		echo '<br />';
		
		//generated list page file
		$this->helpers->html->link('', '', 'name = "index_page"');
		echo '<br />'.LANG_LIST." <a href = '#'>(".LANG_UP.")</a>";
		$this->helpers->htmlx->DisplayHighlightedFile("././app/views/".$this->data[file_name].'/index.php');		
		echo '<br />';
		
		//save/cancel links
		$this->helpers->html->link('/spanel/'.$this->name.'/add/', LANG_OK, "class='button'");
		echo " ";
		$this->helpers->html->link('/spanel/'.$this->name.'/add/'.$this->data[file_name], LANG_CANCEL, "class='button'");
		
	}
//	else
//	{
		$this->helpers->html->Form('');

		//submit table
		$this->helpers->htmlx->SubmitTable("submit", "");
		
		//model variables
		$this->helpers->html->Link(null, '', "name = 'configuration'");
		$this->helpers->html->TableOpen('class = "eva"');
		
			$this->helpers->htmlx->TableHeaderRow(LANG_VARIABLES.'('.LANG_MODEL.')'." <a href = '#'>(".LANG_UP.")</a>", '3');
				
			$this->helpers->htmlx->InputTextRow(LANG_TITLE, 'name', $this->data[name], "onBlur = 'FillForm(\"$this->tablePrefix\", \"$this->storedProcedurePrefix\"); document.getElementById(\"header_logo_link\").focus(); '", '');
			$this->helpers->htmlx->InputTextRow(LANG_SYSTEM_NAME, 'system_name', $this->data[system_name]);
			$this->helpers->htmlx->InputTextRow(LANG_TABLE_NAME, 'table_name', $this->data[table_name], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_DB_CONFIG, 'database_config', $this->data[database_config], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_SP_LIST, 'stored_procedure_list', $this->data[stored_procedure_list], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_SP_LIST_PAGED, 'stored_procedure_list_paged', $this->data[stored_procedure_list_paged], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_SP_UPDATE, 'stored_procedure_update', $this->data[stored_procedure_update], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_SP_GET, 'stored_procedure_get', $this->data[stored_procedure_get], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_SP_DELETE, 'stored_procedure_delete', $this->data[stored_procedure_delete], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_SP_INSERT, 'stored_procedure_insert', $this->data[stored_procedure_insert], '', '');
	
			$this->helpers->htmlx->CheckBoxRow(LANG_GENERATE_MODEL_VARIABLES, "model_variables", $this->data[model_variables]);
			$this->helpers->htmlx->CheckBoxRow(LANG_GENERATE_CONTROLLER_FUNCTIONS, "controller_functions", $this->data[controller_functions]);
			
			//DEPRICATED (for non-table based generation)			
//			$this->helpers->htmlx->CheckBoxRow(LANG_STANDARD_DIRECTORY, "standart_directory", $this->data[standart_directory], "id = 'std_dir' onChange = checkStdDir(this);");
//			$this->helpers->htmlx->CheckBoxRow(LANG_STD_ID, "std_id", $this->data[std_id], "id = 'std_id' style='margin-left: 20px;' onChange = checkStdId(this);");
//			$this->helpers->htmlx->CheckBoxRow(LANG_STD_NAME, "std_name", $this->data[std_name], "id = 'std_name' style='margin-left: 20px;' onChange = checkStdName(this);");
//			$this->helpers->htmlx->CheckBoxRow(LANG_STD_DESCRIPTION, "std_description", $this->data[std_description], "id = 'std_description' style='margin-left: 20px;' onChange = checkStdDescription(this);");	
			
		$this->helpers->html->TableClose('');
		
		//controller variables
		$this->helpers->html->TableOpen('class = "eva"');
		
			$this->helpers->htmlx->TableHeaderRow(LANG_VARIABLES.'('.LANG_CONTROLLER.')', '3');
			
			$this->helpers->htmlx->InputTextRow(LANG_PAGE_TITLE, 'page_title', $this->data[page_title], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_LAYOUT, 'layout', $this->data[layout], '', '');
			$this->helpers->htmlx->InputTextRow(LANG_MODULE, 'module', $this->data[module], '', '');
			
		$this->helpers->html->TableClose('');	
	
		//helper files
		$this->helpers->html->Link(null, '', "name = 'helpers'");
		$this->helpers->html->TableOpen('class = "eva"');
		
			$this->helpers->htmlx->TableHeaderRow(LANG_HELPERS." <a href = '#'>(".LANG_UP.")</a>", '3');
	
			foreach ($this->data[helper_files] as $helper)
			{
				$this->helpers->htmlx->CheckBoxRow($helper, "helpers[$helper]", $this->data[helpers][$helper], "style = 'margin-left: 20px;'");
			}
			
		$this->helpers->html->TableClose('');	
		
		//js files
		$this->helpers->html->Link(null, '', "name = 'js'");
		$this->helpers->html->TableOpen('class = "eva"');
		
			$this->helpers->htmlx->TableHeaderRow(LANG_JS_FILES." <a href = '#'>(".LANG_UP.")</a>", '3');
	
			foreach ($this->data[js_files] as $js_file)
			{
				$this->helpers->htmlx->CheckBoxRow($js_file, "js[$js_file]", $this->data[js][$js_file], "style = 'margin-left: 20px;'");
			}
			
		$this->helpers->html->TableClose('');	
		
		
		//number of fields
		$elements_count = count($this->data[elements]) + 5;
		
		//main form elements
		$this->helpers->html->Link(null, '', "name = 'fields'");
		for ($i=0; $i<$elements_count; $i++)
		{
			$this->helpers->html->Link(null, '', "name = '{$this->data[elements][$i][name]}'");
			$this->helpers->html->TableOpen('class = "eva"');
				
				//main features
				$this->helpers->htmlx->TableHeaderRow(LANG_MAIN_FEATURES." <a href = '#'>(".LANG_UP.")</a>", '3');
				$this->helpers->htmlx->InputTextRow(LANG_APP_NAME, "elements[$i][app_name]", $this->data[elements][$i][app_name], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_NAME, "elements[$i][name]", $this->data[elements][$i][name], "");
				$this->helpers->htmlx->InputTextRow(LANG_TITLE, "elements[$i][title]", $this->data[elements][$i][title], "");
				$this->helpers->htmlx->ComboBoxRow(LANG_TYPE, "elements[$i][type]", $this->field_types, $this->data[elements][$i][type], "id = 'elements[$i][type]'");
				$this->helpers->htmlx->SelectBoxRow(LANG_SUB_TYPE, "elements[$i][sub_type]", $this->field_subtypes, $this->data[elements][$i][sub_type]);
				$this->helpers->htmlx->InputTextRow(LANG_TABLE_NAME, "elements[$i][table_name]", $this->data[elements][$i][table_name], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_LENGTH, "elements[$i][length]", $this->data[elements][$i][length], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_MIN_VALUE, "elements[$i][min_value]", $this->data[elements][$i][min_value], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_MAX_VALUE, "elements[$i][max_value]", $this->data[elements][$i][max_value], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_DEFAULT_VALUE, "elements[$i][default_value]", $this->data[elements][$i][default_value], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_BY_DEFAULT, "elements[$i][by_default]", $this->data[elements][$i][by_default], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_FOREIGN_MODEL, "elements[$i][foreign_model]", $this->data[elements][$i][foreign_model], "", "");
				$this->helpers->htmlx->InputTextRow(LANG_COMMENT, "elements[$i][comment]", $this->data[elements][$i][comment], "", "");
				$this->helpers->htmlx->CheckBoxRow(LANG_PRIMARY_KEY, "elements[$i][primary_key]" , $this->data[elements][$i][primary_key], "id = 'elements[$i][primary_key]'");
				$this->helpers->htmlx->CheckBoxRow(LANG_NOT_NULL, "elements[$i][not_null]" , $this->data[elements][$i][not_null], "id = 'elements[$i][not_null]'");
			
//				//auxiliary features
				$this->helpers->htmlx->TableHeaderRow(LANG_AUXILIARY_FEATURES, '3');
				if ($this->request->post[step] == '1')
				{
					$this->data[elements][$i][in_grid] = 
						((empty($this->data[elements][$i][foreign_model]))&&(!$this->data[elements][$i][primary_key])&&(!in_array($this->data[elements][$i][type], $this->textDataTypes))) ? true : false;
					$this->data[elements][$i][filter] = false;
					$this->data[elements][$i][use_url] = false;
					$this->data[elements][$i][url_controller] = $this->data[controller];
					$this->data[elements][$i][url_action] = $this->defaultGridAction;
					$this->data[elements][$i][url_id] = 'id';
				}
				$this->helpers->htmlx->CheckBoxRow(LANG_DISABLE, "elements[$i][disable]" , $this->data[elements][$i][disable]);
				$this->helpers->htmlx->CheckBoxRow(LANG_SHOW_IN_GRID, "elements[$i][in_grid]" , $this->data[elements][$i][in_grid]);
				$this->helpers->htmlx->CheckBoxRow(LANG_USE_IN_FILTER, "elements[$i][filter]" , $this->data[elements][$i][filter]);
				$this->helpers->htmlx->CheckBoxRow(LANG_USE_URL, "elements[$i][use_url]" , $this->data[elements][$i][use_url], "onChange = 'ShowHideUrlSection(this, $i)'");
				
				//defines whether to use the url options box				
				$url_elements_display = '' ? ($this->data[elements][$i][use_url]) : 'none';
				
				$this->helpers->htmlx->InputTextRow(LANG_CONTROLLER, "elements[$i][url_controller]", $this->data[elements][$i][url_controller], '', '', "style = 'display: $url_elements_display' id = 'url_controller_$i'");
				$this->helpers->htmlx->InputTextRow(LANG_URL_ACTION, "elements[$i][url_action]", $this->data[elements][$i][url_action], '', '', "style = 'display: $url_elements_display' id = 'url_action_$i'");
				$this->helpers->htmlx->InputTextRow(LANG_URL_ID, "elements[$i][url_id]", $this->data[elements][$i][url_id], '', '', "style = 'display: $url_elements_display' id = 'url_id_$i'");
				
			$this->helpers->html->TableClose("");
		}

		//generated stored procedures
		$this->helpers->html->TableOpen('class = "eva"');
			//$i = 0;
			if (!empty($this->data[stored_procedures]))
			{
				foreach ($this->data[stored_procedures] as $key=>$value)
				{
//					$this->helpers->html->JavaScript("editAreaLoader.init({id : 'generated_$key', syntax: 'sql', toolbar: 'search, go_to_line, |, undo, redo, |, syntax_selection, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help'});");
					$this->helpers->htmlx->TextareaRow($key." <a href = '#'>(".LANG_UP.")</a><a name = '$key'></a>", "stored_procedures[$key]", $value, 'id="generated_'.$key.'" name="content" style="height: 450px; width: 100%;"');
					
					//SpherusFileEditor::LoadEditor($value, array('id'=>'generated'.$i));
					//SpherusFileEditor::LoadEditorRow($key." <a href = '#'>(".LANG_UP.")</a><a name = '$key'></a>", "storedprocedures$i", $value, array('id'=>'generated'.$i));
					//$i++;
					
					//$this->helpers->htmlx->TextareaRow($key." <a href = '#'>(".LANG_UP.")</a><a name = '$key'></a>", "stored_procedures[$key]", $value, "id = '$key' style = 'width: 100%; height: 200px'");
					$this->helpers->htmlx->CheckboxRow(LANG_GENERATE, "generate[$key]", true, "onChange = 'if (!this.checked) {document.getElementById(\"generated_$key\").disabled = \"disabled\"} else {document.getElementById(\"generated_$key\").removeAttribute(\"disabled\")}'");
					echo "<tr><td colspan = '3'><hr /></td></tr>";
				}
			}
		$this->helpers->html->TableClose("");

		//submit table
		$this->helpers->htmlx->SubmitTable("submit", "");
			
		$this->helpers->html->FormClose();
	//}
?>